package com.zx.flow.db.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@MapperScan(basePackages = "com.zx.flow.db.dao", sqlSessionTemplateRef = "sqlSessionTemplate")
@Configuration
public class DataSourceConfig {

//    @Bean("dataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.druid")
//    public DataSource getDataSource() {
//        return DruidDataSourceBuilder.create().build();
//    }
// 下面的3个配置，会把mybatisplus的dataSource覆盖带掉
//    @Bean("sqlSessionFactory")
//    public SqlSessionFactory sessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        return bean.getObject();
//    }
//
//    @Bean("sqlSessionTemplate")
//    public SqlSessionTemplate sqlTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//    @Bean(name = "dataSourceTransactionManager")
//    public DataSourceTransactionManager dataSourceTx(@Qualifier("dataSource") DataSource dataSource) {
//        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
//        dataSourceTransactionManager.setDataSource(dataSource);
//        return dataSourceTransactionManager;
//    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }


}